<?php
/**
 * Created by PhpStorm.
 * User: wuz
 * Date: 2016/8/11
 * Time: 14:53
 */
namespace Ycf\Lesson\CookieAndSession\Cookie;

/*Cookie类
 * */
class Cookie
{
    private $cookieName;
    private $cookieValue;
    private $cookieTime;
    public function __construct($cookieName, $cookieValue = null, $cookieTime)
    {
        $this->cookieName = $cookieName;
        $this->cookieTime = $cookieTime;
        if ($cookieValue !== null) {
            $this->cookieValue = $cookieValue;
        }
    }

    //创建Cookie
    public function set()
    {
        setcookie($this->cookieName, $this->cookieValue, time() + $this->cookieTime);

    }

    //获取Cookie
    public function getCookie()
    {
        if (isset($_COOKIE[$this->cookieName])) {
            return $_COOKIE[$this->cookieName];
        } else {
            return "1111";
        }
    }

    //删除Cookie
    public function deleteCookie()
    {
        $this->cookieValue = "";
        $this->cookieTime  = time() - 600;
        return $this->set();
    }
}
